<template>
  <!-- 添加或修改转场单申请处置对话框 -->
  <el-dialog
    :title="title"
    :visible.sync="dialogVisible"
    width="1000px"
    append-to-body
    :close-on-click-modal="false"
    @close="close"
  >
    <el-form
      ref="form"
      :model="form"
      :rules="rules"
      label-width="100px"
      label-position="right"
      class="flex-form"
    >
      <el-form-item label="批次号" prop="manifestId">
        <el-input v-model.trim="form.manifestId" placeholder="请输入批次号" />
      </el-form-item>
      <el-form-item label="单证号" prop="billCode">
        <el-input v-model.trim="form.billCode" placeholder="请输入单证号" />
      </el-form-item>
      <!-- <el-form-item label="0未提交，1已提交" prop="status">
        <el-select
          v-model.trim="form.status"
          placeholder="请选择0未提交，1已提交"
        >
          <el-option
            v-for="dict in dict.type.sys_yes_no"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          ></el-option>
        </el-select>
      </el-form-item> -->
      <!-- <el-form-item label="场所号" prop="fieldCode">
        <el-input v-model.trim="form.fieldCode" placeholder="请输入场所号" />
      </el-form-item> -->
      <el-form-item label="处置说明" prop="urgNote">
        <el-input v-model.trim="form.urgNote" type="textarea" placeholder="请输入处置说明" />
      </el-form-item>
      <el-form-item label="上传附件" prop="attachFile">
        <fileUpload v-model.trim="form.attachFile" :fileSize="1" :fileType="['pdf']"/>
      </el-form-item>
      <!-- <el-form-item label="附件后缀名" prop="suffix">
        <el-input v-model.trim="form.suffix" placeholder="请输入附件后缀名" />
      </el-form-item> -->
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">保 存</el-button>
      <el-button @click="close">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import {
  getTransferUrginfo,
  addTransferUrginfo,
  updateTransferUrginfo,
} from "@/api/system/transferUrginfo";
export default {
  name: "TransferUrginfo-addEdit",
  props: {
    dialogType: {
      type: String,
      default: "add",
    },
    rowData: {
      type: Object,
      default: () => {},
    },
    dict: {}
  },
  data() {
    return {
      // 弹出层
      dialogVisible: false,
      // 标题
      title: "新增",
      // 表单参数
      form: {
        billCode: null,
        manifestId: null,
        id: null,
        // status: null,
        // fieldCode: null,
        attachFile: null,
        // suffix: null,
        urgNote: null,
        // createBy: null,
        // createTime: null,
      },
      // 转场单申请处置表格数据
      transferUrginfoList: [],
      // 表单校验
      rules: {
        manifestId: [{
          required: true,
          message: '批次号不能为空',
          trigger: 'blur'
        },],
        urgNote: [{
          required: true,
          message: '处置说明不能为空',
          trigger: 'blur'
        },],
        attachFile: [{
          required: true,
          message: '附件不能为空',
          trigger: 'blur'
        },],
      },
    };
  },
  methods: {
    open() {
      this.dialogVisible = true;
      this.$nextTick(() => {
        if (this.dialogType == "add") {
          this.title = "新增";
        } else if (this.dialogType == "edit") {
          this.title = "编辑";
          this.loadDetail();
        } else if (this.dialogType == "detail") {
          this.title = "详情";
          this.loadDetail();
        }
      });
    },
    close() {
      this.$refs["form"].resetFields();
      this.dialogVisible = false;
    },
    // 获取详情
    loadDetail() {
      const billCode = this.rowData.id;
      getTransferUrginfo(billCode).then((res) => {
        if (res.code == 200 && res.data) {
          this.form = res.data;
        }
      });
    },
    // 提交表单
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          let params = {
            ...this.form,
          };
          if (this.dialogType == "add") {
            addTransferUrginfo(this.form).then((res) => {
              if (res.code === 200) {
                this.$modal.msgSuccess("新增成功");
                this.close();
                this.$emit("handleQuery");
              }
            });
          } else {
            params.id = this.rowData.id;
            updateTransferUrginfo(this.form).then((res) => {
              if (res.code === 200) {
                this.$modal.msgSuccess("修改成功");
                this.close();
                this.$emit("handleQuery");
              }
            });
          }
        }
      });
    },
  },
};
</script>

<style lang="scss" scoped></style>